package cn.battlecruiser.vishnu.auth.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import cn.battlecruiser.vishnu.auth.feign.UserService;
import cn.battlecruiser.vishnu.auth.userdetails.UserDetailsImpl;
import cn.battlecruiser.vishnu.common.model.Userinfo;


@Service("userDetailService")
public class UserDetailServiceImpl implements UserDetailsService {
    @Autowired
    private UserService userService;

    @Override
    public User loadUserByUsername(String username) throws UsernameNotFoundException {
    	//TODO:这里应该查出角色出来
        Userinfo userVo = userService.findUserByUsername(username);
        List<SimpleGrantedAuthority> authorities = new ArrayList<SimpleGrantedAuthority>();
        authorities.add(new SimpleGrantedAuthority("roleA"));
		
        User userDetails = new UserDetailsImpl(userVo, authorities);
        return userDetails;
    }
}
